<div class="page-container">
	<h1 class="header"><i><?php echo $this->page->title ?></i></h1>
	<div class="content"><?php //echo stripslashes($this->page->text) 
		preg_match_all('/\$(audio|video)\=([a-zA-Zа-яА-я0-9_\-\=\+\/\|\?\:\;\.\,\%\&]+)\$/', stripslashes($this->page->text), $m);
		$count = count($m[0]);
		$content = stripslashes($this->page->text);
		for ($i=0; $i<$count; $i++) {
			if ($m[1][$i] == 'audio') {
				$content = strtr(
					$content,
					array($m[0][$i] => '<audio src="' . $m[2][$i] . '" type="audio/mp3" controls="controls"></audio>')
				);
			} elseif ($m[1][$i] == 'video') {
				$content = strtr(
					$content,
					array($m[0][$i] => '<video src="' . $m[2][$i] . '" type="video/mp4" controls="controls"></audio>')
				);
			}
		}
		preg_match_all('/\$(album)\=([0-9]+)\$/', $content, $m);
		$count = count($m[0]);
		for ($i=0; $i<$count; $i++) {
			$select = Model_PhotoAlbums::getInstance()->select()->from('photo_albums', array('id', 'title'));
			$select->where('id = ?', $m[2][$i]);
			$albumRow = Model_PhotoAlbums::getInstance()->fetchRow($select);
			if ($albumRow) {
				$selectPhotos = Model_AttachmentsForAlbums::getInstance()->select()->limit(1);
				$photoId = $albumRow->findDependentRowset('Model_AttachmentsForAlbums', 'Album', $selectPhotos)->current();
				if (count($photoId) > 0) {
					$photoSelect = Model_Attachments::getInstance()->select()->from('attachments', array('url'));
					$photo = $photoId->findParentRow('Model_Attachments', 'Attachment', $photoSelect);
					ob_start();
					echo '<a href="/album?id=' . $albumRow->id . '" target="_blank">
							<img src="'.$photo->url.'" height="110" alt="'.$albumRow->title.'" />
						</a>';
					$contents = ob_get_contents();
					ob_end_clean();
					$content = strtr(
						$content,
						array($m[0][$i] => $contents)
					);
				}
			}
		}
		preg_match_all('/\$(news)\=([0-9]+)\(([0-9]*)\)\$/', $content, $m);
		$count = count($m[0]);
		for ($i=0; $i<$count; $i++) {
			$select = Model_NewsGroup::getInstance()->select()
					->where('group_id = ?', $m[2][$i]);
			$newsAll = Model_NewsGroup::getInstance()->fetchAll($select);
			if (count($newsAll) > 0) {
				foreach ($newsAll as $newsRow) {
					$newsSelect = Model_News::getInstance()->select()->from('news', array('id', 'title', 'url_key', 'author_id', 'created'));
					if (!empty($m[3][$i])) {
						$newsSelect->limit($m[3][$i]);
					}
					$news = $newsRow->findParentRow('Model_News', 'News', $newsSelect);
					ob_start();?>
						<div class="news-wrap">
							<div class="news-header" style="border-bottom: 0px;">
								<?php echo $news->title ?>
							</div>
							<div class="news-info">
								<b>Создано: </b><?php
									$date = new Zend_Date($news->created, false, Pidguin_Application::getInstance()->getLocale());
									echo $date->toString('dd MMMM YYYYг. в HH:mm');
								?>,
								<b>Автор: </b><?php echo $news->findParentRow('Model_User')->name ?>,
								<b>Комментарий: </b><?php echo count($news->findDependentRowset('Model_NewsComments')) ?>
								<div class="right" style="display: inline-block; float: right;">
									<a href="/news/<?php echo $news->url_key ?>" target="_blank" alt="Откроется в новом окне">Открыть новость</a>
								</div>
							</div>
						</div>
					<?php
					$contents = ob_get_contents();
					ob_end_clean();
					$content = strtr(
						$content,
						array($m[0][$i] => $contents)
					);
				}
			}
		}
		echo $content;
	?></div>
	<div class="info-block">
		<b>Опубликовано:</b> <?php echo $this->date ?> в <?php echo $this->time ?>, 
		<b>Автор:</b> <?php echo $this->author->name ?>
	</div>
</div>
